package com.xunhang.controller;

import com.xunhang.dto.Result;
import com.xunhang.entity.Type;
import com.xunhang.service.impl.TypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/type")
@Tag(name = "类型模块")
@CrossOrigin(origins = "*")
public class TypeController {

    @Autowired
    TypeService typeService;
    @Operation(summary = "获取所有type")
    @GetMapping
    public Result queryAllType(){
        return typeService.queryAllType();
    }

    @Operation(summary = "增加type,type里不用给id")
    @PostMapping
    public Result AddType(@RequestBody Type type){
        return typeService.AddType(type);
    }

    @Operation(summary = "删除type")
    @DeleteMapping("/{id}")
    public Result DeleteType(@PathVariable("id") Integer id){
        return typeService.DeleteType(id);
    }

    @Operation(summary = "更新type，type里需要id")
    @PutMapping()
    public Result UpdateType(@RequestBody Type type){
        return typeService.UpdateType(type);

    }

    @Operation(summary = "获取特定type")
    @GetMapping("/{id}")
    public Result queryTypeById(@PathVariable("id") Integer id){
        return typeService.queryTypeById(id);
    }

}
